<!--项目列表-->
<template>
  <div>
    <el-form ref="form" :model="form" :inline="true" style="text-align: left;">
      <el-form-item>
        <el-input v-model="form.filter.kwd" style="float: left;" placeholder="请输入项目名称"></el-input>
      </el-form-item>
      <el-form-item>
        <el-select v-if="$utils.getRoleCodeList().indexOf('SITE_MANAGER')==-1" v-model="form.filter.fieldList[0].val" style="width:200px;">
          <el-option label="全部" value=""></el-option>
          <el-option
            v-for="item in siteList"
            :label="item.name"
            :value="item.id">
          </el-option>
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" style="float: left;" @click.native="onSubmit"><i class="el-icon-search"></i>查询
        </el-button>
        <el-button v-if="$utils.ckUIPower('S01030101')" @click="openEditDialog" style="float: left;"><i
          class="el-icon-plus"></i>新增
        </el-button>
      </el-form-item>
    </el-form>
    <div>
      <el-table stripe
                v-loading="loading"
                element-loading-text="数据加载中"
                :data="page.list"
                style="width:100%"
                @sort-change="onSubmit"
                border>
        <el-table-column
          inline-template
          fixed
          label="序号"
          width="80"
          align="center">
          <span>{{$index + 1 + ((page.pageNumber - 1) * page.pageSize)}}</span>
        </el-table-column>
        <el-table-column
          property="name"
          sortable="custom"
          label="名称"
          width="150"
          align="center">
        </el-table-column>
        <!--<el-table-column
          property="pinyin"
          sortable="custom"
          label="项目拼音简写"
          width="150"
          align="center">
        </el-table-column>-->
        <el-table-column
          label="方案编号"
          property="num"
          sortable="custom"
          width="150"
          align="center">
        </el-table-column>
        <el-table-column
          label="中心"
          property="siteName"
          sortable="custom"
          width="150"
          align="center">
        </el-table-column>
        <el-table-column
          sortable="custom"
          property="createDatetime"
          label="创建时间"
          width="180"
          align="center">
        </el-table-column>
        <el-table-column
          inline-template
          sortable="custom"
          property="status"
          label="状态"
          width="150"
          align="center"
        >
          <template>
             <span>
              {{statusList[row.status].label}}
            </span>
          </template>
        </el-table-column>
        <el-table-column
          inline-template
          label="操作"
          fixed="right"
          align="center"
          vif="$utils.ckUIPower('S01010101')"
          >
          <template>
            <el-button type="text" @click.native="openEditDialog(row.id)" size="small" v-if="row.status==0">编辑</el-button>
            <el-popover
              ref="popover_del"
              placement="top"
              :key="'popover_del'+row.id"

            >
              <p><img style="vertical-align:middle;" src="../../../../static/img/ques.png" height="25" width="25"/>确定要删除项目【{{row.name}}】吗？</p>
              <div style="text-align: right;">
                <el-button type="primary" size="mini" @click.native.prevent="deleteProject(row.id);">确定</el-button>
              </div>
            </el-popover>
            <el-button type="text" v-popover:popover_del size="small" class="red" v-if="row.status==0"><i class="el-icon-delete"></i>删除
            </el-button>
            <el-button type="text" @click.native="DesignProcess(row)" :key="'designProcess'+row.id" size="small" v-if="row.status==0">项目设计</el-button>
            <el-button type="text" @click.native="openConfigSiteDialog(row)" size="small" v-if="row.status==0&&$utils.getRoleCodeList().indexOf('SITE_MANAGER')==-1">配置中心</el-button>
            <el-button type="text" @click.native="openConfigAccountsDialog(row)" size="small" v-if="row.status==0">配置用户</el-button>

            <el-popover
              ref="popover_"
              placement="top"

            >
              <p><img style="vertical-align:middle;" src="../../../../static/img/ques.png" height="25" width="25"/>是否要将{{row.name}}[{{row.num}}]的状态变更为{{statusList[row.status + 1].label}}?</p>
              <div style="text-align: right;">
                <el-button type="primary" size="mini" @click.native.prevent="changeActive(row.id,row.status);">
                  确定
                </el-button>
                <!-- <el-button size="mini" @click.native.prevent="row.p1=false">取消</el-button> -->
              </div>
            </el-popover>
            <el-button type="text" :key="'changestatus'+row.id" v-if="row.status!=2" size="small" v-popover:popover_>状态变更</el-button>
          </template>
          
        </el-table-column>
      </el-table>
    </div>
        <template>
          <el-dialog
            title="项目设计"
            :visible.sync="dialogBox"
            class='sheji'>
            <div class="diaCenBox">
              <el-button type="primary" @click.native="openDesignDialog(row)"   >采血点设计</el-button>
              <el-button type="primary"  @click.native="openDischargeDialog(row)">入排标准</el-button>
              <el-button type="primary" @click.native="openProblemDialog(row)">问题设计</el-button>
              <el-button type="primary" @click.native="uploadConsent(row)">上传知情同意</el-button>
              <el-button type="primary" @click.native="codingRules(row)">筛选号规则</el-button>
            </div>
            <span slot="footer" class="dialog-footer">
              <el-button type="primary" @click="dialogBox = false">取消</el-button>
            </span>
          </el-dialog>
        </template>
  
    <div class="block">
      <el-pagination
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page="page.pageNumber"
        :page-sizes="[10, 20, 30]"
        :page-size="10"
        layout="total, prev, pager, next, jumper"
        :total="page.totalRow">
      </el-pagination>
    </div>
    <!-- 上传知情同意 -->
    <el-dialog
      title="上传知情同意"
      :visible.sync="toKnow"
      :before-close="toKnowClose"
      class='toKnowSS'>
      
      <div>
          <form :action="acUrl" method="post" target="nm_iframe" enctype='multipart/form-data'  >
            <input type="file" name='file' class='Allfile'id='ffile' @change='subbmingCange($event)'  style="display:none;"/>
            <div class='submitAClass'>

              <input type="button" @click='filedis()' class='submitA' value="点击上传"  />
              <span>
                {{fileTxt}}
              </span>
            </div>
            <div  class='submitAClass  ris'>
              <input type="submit" @click='subbming()' class='submitA'/>
            </div>
            
          </form>
          <iframe id="id_iframe" name="nm_iframe" style="display:none;"></iframe>
           <!--  <el-upload
              class="upload-demo"
              ref="upload"
              name="file"
              action="http://192.168.1.178:9090/api/pt/project/upIknow"
              :on-preview="handlePreview"
              :on-remove="handleRemove"
              :file-list="fileList"
              :auto-upload="false"
              :headers="objDA"
              :data="tokenS">
              <el-button slot="trigger" size="small" type="primary">选取文件</el-button>
              <el-button style="margin-left: 10px;" size="small" type="success" @click="submitUpload">上传到服务器</el-button>
              <div slot="tip" class="el-upload__tip">只能上传jpg/png文件，且不超过500kb</div>
          </el-upload> -->
          
        
        </div>
              
            
      
          <!-- <span slot="footer" class="dialog-footer">
          <el-button type="primary" @click="toKnowY()">确 定</el-button>
            <el-button @click="toKnowClose()">取 消</el-button>
            
          </span> -->

    </el-dialog>
    <!-- 筛选号规则 -->
    <el-dialog
      title="筛选号规则"
      :visible.sync="iScodingRules"
      :before-close="codingRulesClose"
      class='toKnowSS'>
      
      <div>
          
          筛选号：以<el-input type="age" v-model="pharmacy_rate" class='allinputs'></el-input> 开头 

          &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;位数：<el-select v-model="rulesNum" placeholder="请选择" class='allinput'>
                      <el-option
                        v-for="item in rulesNumArr"
                        :key="item"
                        :label="item"
                        :value="item">
                      </el-option>
                    </el-select>
          <div  class='submitAClass  ris'>
              <el-button type="primary" class="addBing guomin"  @click='rulessub()'>提交</el-button>
            </div>
          
        
        </div>
              
            
      

    </el-dialog>
    <!--弹出框-->
    <project-add-dialog v-bind:dialog-form-visible="dialogData.show" v-bind:project-id="projectId" v-bind:id="id"
                        v-on:closeDialog="closeDialog"></project-add-dialog>
    <!--项目流程设计-->
    <design-dialog :add-process-visible="designDialog.show" :project-id="projectId"
                   :project-name="projectName"></design-dialog>
                   <!-- 问题流程设计-->
    <discharge-dialog :add-process-visible="dischargeDialog.show" :project-id="projectId"
                   :project-name="projectName"></discharge-dialog>
                    <!-- 入排标准设计-->
    <problem-dialog :add-process-visible="problemDialog.show" :project-id="projectId"
                   :project-name="projectName"></problem-dialog>
    <!--项目中心配置-->
    <config-site-dialog v-bind:dialog-form-visible="configSiteDialog.show" :project-id="projectId"
                        :project-name="projectName"></config-site-dialog>
    <!--项目用户配置-->
    <config-account-dialog :dialog-form-visible="configAccountsDialog.show" :project-id="projectId"
                           :project-name="projectName" :site-id="siteId"></config-account-dialog>
  </div>
</template>
<script>
  import ProjectAddDialog from './add.dialog.vue'
  import DesignDialog from './design.dialog.vue'
  import ProblemDialog from './problem.dialog.vue'
  import DischargeDialog from './discharge.dialog.vue'
  import http from '../../../api/http'
  import ConfigSiteDialog from './configSites.vue'
  import ConfigAccountDialog from './configAccounts.vue'
  import store from '../../../store'

  export default {
    data() {
      return {
        statusList: [{
          value: 0,
          label: '设计中'
        }, {
          value: 1,
          label: '试验中'
        }, {
          value: 2,
          label: '已停止'
        },{
          value: 3,
          label: '-'
        }],
        objDA:{
          "Content-Type":"multipart/form-data"
        },
        fileTxt:'',
        toKnow:false,
        statusNum: null,
        loading: true,
        form: {
//          status: 0,
          filter: {kwd: '', sort: {create_datetime: 'desc'},fieldList:[{field:'siteId',exp:'=',val:''}]},
          pageNo: 1,
          pageSize: 10
        },
        id: null,
        dialogData: {show: false},
        designDialog: {show: false},
        dischargeDialog: {show: false},
        problemDialog:{show:false},
        configSiteDialog: {show: false},
        configAccountsDialog: {show: false},
        page: {},
        projectId: '',
        projectName: '',
        siteId:'',
        siteList:[],
        projectStatus:null,
        dialogBox:false,
        fileList:[],
        iScodingRules:false,
        tokenS:{},
        acUrl:"",
        fileIS:[],
        rulesNumArr:[2,3],
        rulesNum:'2',
        pharmacy_rate:'',
        ppID:'',
      }
    },
    computed: {},
    methods: {
      //筛选号规则开启
      codingRules(row){
        var vm=this;
        vm.rulesNum='2';
        vm.pharmacy_rate='';
        vm.ppID=vm.projectId;
        vm.iScodingRules=true;

      },
      //筛选号规则关闭
      codingRulesClose(){
        var vm=this;
        vm.rulesNum='2';
        vm.pharmacy_rate='';
        vm.ppID='';
        vm.iScodingRules=false;
      },
      // 提交编码规则
      rulessub(){
        var vm=this;
          if(vm.pharmacy_rate==''){
            vm.$message.error({title: '操作失败', message: "填写完整信息"});
            return;
          }
          http.postData(vm, "/pt/candidateSubjects/setCoding",{id:vm.ppID,begin:vm.pharmacy_rate,digit:vm.rulesNum}, function (resp) {
            var ret = resp.body;
            console.log(resp)
            if (ret.code === '111') {
              vm.$message.success({title: '操作完成', message: ret.msg});
              vm.iScodingRules=false;
            } else {
              vm.$notify.error({title: '操作完成', message: ret.msg});
            }
          });
      },
      filedis(){
        document.getElementById('ffile').click();
      },
      // 上传知情BOX
      uploadConsent(row){
        this.toKnow=true;
       this.acUrl="http://192.168.1.178:9090/api/pt/project/upIknow?login_token="+store.getters.getCurrentLoginInfo.login_token+"&proid="+this.projectId;
       // this.tokenS={
       //  login_token:store.getters.getCurrentLoginInfo.login_token,
       //  proid:this.projectId
       // }
       
    
      },
      toKnowClose(){
        this.toKnow=false;
        this.fileTxt='';
      },
      submitUpload() {
        // console.log(this.acUrl)
        // console.log(store.getters.getCurrentLoginInfo.login_token)
         console.log(this.$refs.upload)
        this.$refs.upload.submit();
      },
      handlePreview(file) {
        console.log(file);
      },
      handleRemove(file, fileList) {
        console.log(file, fileList);
      },
      subbmingCange(event){
        this.fileTxt=event.srcElement.files[0].name;
        // console.log(event.srcElement.files[0])
        this.fileIS=event.srcElement.files;
      },
      subbming() {
        if(this.fileTxt==''){
          this.$message.error({title: '操作失败', message: "请重新上传"});
           this.fileTxt='';
        }else{
          this.$message.success({title: '操作提示', message:"上传成功"});
            this.toKnow=false;
             this.fileTxt='';
        }
        
      
      },
      toKnowY(){
        var vm =this;
           

         http.postData(vm, "/pt/project/upIknow/"+vm.projectId,{file:JSON.stringify(vm.file)}, function (resp) {
            var ret = resp.body;
            if (ret.code === '111') {
              vm.$message.success({title: '操作成功', message: ret.msg});
            } else {
              vm.$notify.error({title: '操作失败', message: ret.msg});
            }
          });
      },
     // tirggerFile(event){

     //  this.file = event.target.files;
     //  console.log(this.file)
     // },
        changeProjectActive(vm,id,status){
          http.postData(vm, "/pt/project/changeActive/" + id + "-" + status,{}, function (resp) {
            var ret = resp.body;
            if (ret.code === '111') {
              vm.$message.success({title: '操作成功', message: ret.msg});
            } else {
              vm.$notify.error({title: '操作失败', message: ret.msg});
            }
          });
        },
        flashData(vm){
          http.postData(vm, "/pt/project/page", {
            json: JSON.stringify(vm.form.filter),
            pageNo: vm.form.pageNo,
            pageSize: vm.form.pageSize
          }, function (resp) {
            var ret = resp.body;
            if (ret.code == '111') {
              vm.page = ret.value;
            }
            vm.loading = false;
          });
        },
      /**
       * 变更项目状态
       */
      changeActive(id,rowStatus){
        var vm = this;
        var status = rowStatus;
        if(status == 0){
            status = 1;
          vm.changeProjectActive(vm,id,status);
          vm.flashData(vm);
        }else if(status == 1){
          vm.$confirm('此操作后将无法操作项目, 是否继续?', '提示', {
            confirmButtonText: '确定',
            cancelButtonText: '取消',
            type: 'warning'
          }).then(
              () => {
                status = 2;
                vm.changeProjectActive(vm,id,status);
                vm.flashData(vm);
              }
            ).catch(() => {
            return false;
          });
        }
      },
      /**
       * 关闭配置用户弹窗
       */
      closeConfigAccountsDialog() {
        this.configAccountsDialog.show = false
      },
      /**
       * 打开选择用户弹窗
       */
      openConfigAccountsDialog(row) {
        this.projectName = row.name;
        this.projectId = row.id;
        this.siteId = row.siteId;
        this.configAccountsDialog.show = true
      },
      /**
       * 关闭选择中心弹框
       */
      closeSitesDialog() {
        this.sitesDialog.show = false
      },
      openSitesDialog(row) {
        this.projectId = row.id;
        this.projectName = row.name;
        this.sitesDialog.show = true
      },
      openDesignDialog(row) {
        // this.projectId = row.id;
        // this.projectName = row.name;
        this.designDialog.show = true;
      },
      openDischargeDialog(){
        this.dischargeDialog.show = true;
      },
      openProblemDialog(row){
        this.problemDialog.show = true;
      },
      openConfigSiteDialog(row) {
        this.projectId = row.id;
        this.projectName = row.name;
        this.configSiteDialog.show = true;
      },
      closeConfigSiteDialog() {
        this.configSiteDialog.show = false;
      },
      closeDischargeDialog(){
        this.dischargeDialog.show = false;
      },
      DesignProcess(row){
        this.projectId = row.id;
        this.projectName = row.name;
        this.dialogBox = true;
      },
      onSubmit(sortCol) {
        var vm = this;
        if (sortCol && sortCol.prop != undefined && sortCol.prop != '' && sortCol.prop != 'undefined') {
          var sortJson = '{"' + sortCol.prop + '":"' + (sortCol.order == 'descending' ? 'desc' : 'asc') + '"}';
          vm.form.filter.sort = JSON.parse(sortJson);
          vm.form.pageNo = 1;
        }
        vm.loading = true;

        http.postData(vm, "/pt/project/page", {
          json: JSON.stringify(vm.form.filter),
          pageNo: vm.form.pageNo,
          pageSize: vm.form.pageSize
        }, function (resp) {
//            console.log(resp)
          var ret = resp.body;
          if (ret.code == '111') {
            vm.page = ret.value;
//            console.log(vm.page)
          }
          vm.loading = false;
        });
      },
      openEditDialog(id_) {
        this.$set(this.dialogData, 'show', true);
        if (id_ != undefined && typeof id_ == "string") {
          this.id = id_;
        } else {
          this.id = '';
        }
      },
      closeDialog() {
        this.dialogData.show = false;
      },
      closeDesignDialog() {
        this.designDialog.show = false;
      },
      closeProblemDialog(){
          this.problemDialog.show = false;
      },
      deleteProject(id) {
        var vm = this;
        http.postData(vm, "/pt/project/del/" + id, {}, function (resp) {
          var ret = resp.body;
          if (ret.code === '111') {
            vm.$notify({title: '删除提示', message: ret.msg, type: 'success'});
            vm.onSubmit();
          } else {
            vm.$message({type: 'error', message: ret.msg});
          }
        });
      },
      handleSizeChange(){
        this.form.pageNo = 1
        this.onSubmit()
      },
      handleCurrentChange(val) {
        this.form.pageNo = val
        this.onSubmit()
      }
    },
    components: {
      ProjectAddDialog,
      DesignDialog,
      ProblemDialog,
      ConfigSiteDialog,
      ConfigAccountDialog,
      DischargeDialog
    },
    created() {
      this.onSubmit();
      var vm=this;
      var id = vm.$router.currentRoute.query.pushSiteId;
      //获取中心
      if(id!=null&&id!=""){
        vm.form.filter.fieldList[0].val = id;
        vm.onSubmit();
      }
      http.postData(vm,'/pt/site/list',{},function (res) {
        if (res.body.code == '111')
          vm.siteList = res.body.value;
      });
    },
  }
</script>
<style>
  .diaCenBox{
    text-align: center;
    margin:20px 0 0px 0;
  }
  .diaCenBox button{
    margin:30px 30px;
  }

 .sheji .el-dialog--small {
    width: 50%;
    border-radius: 15px;
}
.sheji .el-dialog__header{
  border-radius: 15px 15px 0 0;
}
.toKnowSS .el-dialog--small{
    width: 50%;

}
.submitA{
  background-color:#78c5a5;
  color:#fff;
  border-radius: 5px;
  border: none;
  padding: 10px 15px;
  cursor:pointer;

}
.submitAClass{
  margin:20px 0;
}
.ris{
  text-align: right;
}
.allinput{
  width:70px;
}
.allinputs{
  width:50px;
  margin:0 10px;
}
</style>
